<template>
    <div class="container">
        <div class="middle">
            <el-table ref="multipleTable" :data="tableData" stripe tooltip-effect="dark" style="width: 100%">
                <!-- <el-table-column label="脚本id" prop="taskId" width="130px"></el-table-column> -->
                <el-table-column label="脚本名称" prop="taskName"></el-table-column>
                <el-table-column label="描述" prop="taskNote"></el-table-column>
                <el-table-column label="cron表达式" prop="cron" width="200px"></el-table-column>
                <el-table-column label="状态" prop="state" width="130px">
                    <template slot-scope="scope">
                        <span>{{ getState(scope.row.state) }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="日志" prop="detail"></el-table-column>
                <!-- <el-table-column label="操作">
                    <template slot-scope="scope">
                      <el-button v-if="scope.row.state !='1'" v-loading.fullscreen.lock="fullscreenLoading" type="success" @click="xingdong(scope.row)" size="small" plain>执行</el-button>
                      <el-button v-if="scope.row.state !='1'" type="success" @click="check(scope.row.taskId,1)" size="small" plain>执行</el-button> 
                      <el-button v-if="scope.row.state !='0'" type="success" @click="check(scope.row.taskId,0)" size="small" plain>取消执行</el-button> 
                    </template>
                </el-table-column> -->
            </el-table>
        </div>
        <el-dialog
            title="提示"
            :visible.sync="dialogVisible"
            width="30%">
            <span>{{con}}</span>
            <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>
          </el-dialog>
    </div>
</template>

<script>
  window._interceptConfig = {
    collection: true, //整体开关
    click: true, //页面点击事件信息采集开关
    page: true, //页面跳转加载事件信息采集开关
    error: true, //异常信息采集开关
    http: true, //通讯信息采集开关
    name: "jyzdhywxxxtsdfx_n_prd.mart-ui-ds", //系统编号，被采集信息的系统名称。前端简称
    url: " http://apm.sd.sgcc.com.cn:19411/api/v2/spansWeb"//数据上报服务地址，根据实际情况输入
  };
</script>
<!-- src -->
<script src=" http://25.41.37.249:19411/assets/js/intercept.min.js " async></script>
<script>
  import { queryScriptApp ,updateScriptAppById } from "@/api/system/analysisview"
  import { addHistory } from "@/api/system/devops"
    export default {
        name: 'Hardscript',
        data() {
            return {
              fullscreenLoading:false,
              con:'',
              dialogVisible:false,
                // 表格数据
                tableData: null,
                // 功能编号
                model: 4
            }
        },
        methods: {
          xingdong(val){
            this.fullscreenLoading = true;
            addHistory(val).then(resp=>{
              this.con = resp.msg
              this.fullscreenLoading = false
              this.dialogVisible = true
            })
          },
            // 加载数据
            initData() {
                queryScriptApp(this.model).then(response => {
                    this.tableData = response.data
                })
            },

            // 返回状态
            getState(code) {
                if (code === '0') {
                    return '正常'
                } else if (code === '1') {
                    return '停用'
                }
            },
            // 执行
          check(id,st) {
              console.log("开始")
            let text = ''
            if(st === 0){
              text = '取消执行'
            }else {
              text = "立即执行"
            }

            this.$confirm('要'+ text +'此脚本吗?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              if(st === 0){
                this.$message({
                  type: 'success',
                  message: '脚本'+id+text
                })
              }else {
                this.$message({
                  type: 'success',
                  message: '脚本'+id+text+"请在脚本运行时间结束后前往健康评分体系管理查看"
                })


              }
              updateScriptAppById(id,st).then(response => {
                //回显
                this.initData()
              })


            })
          },

        },
        mounted() {
            this.initData()
        }
    }

</script>

<style>
    .middle {
        margin: 10px;
        width: 100%;
    }
</style>
